package com.zzjson.thread.atomic;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.thread.atomic</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年08月14日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class AtomicThreadDemo {
	public static int threadCount = 5000;
	public static int count = 0;

	public static void main(String[] args) {
		CountDownLatch countDownLatch = new CountDownLatch(threadCount);
		ExecutorService executorService = Executors.newFixedThreadPool(1000);
		for (int i = 0; i < threadCount; i++) {
			executorService.execute(new Runnable() {
				@Override
				public void run() {
					System.out.println(count);
					count++;
					countDownLatch.countDown();
				}
			});

		}
		try {
			countDownLatch.await();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		executorService.shutdown();
		System.out.println(countDownLatch.getCount());
		System.out.println(count);

	}
}